/**
 * Created by 鄢鹏权 on 2017/04/08.
 */
namespace Castle {
    export class Cookie {
        static set(name: string, value: string) {
            let Days = 30;
            let exp: Date = new Date();
            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toTimeString();
        }

        static get(name) {
            let arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return decodeURI(arr[2]);
            else
                return null;
        }

        static clear() {
            document.cookie = ''
        }
    }
}